package com.online.onlineshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.online.onlineshop.entity.Orders;
import com.online.onlineshop.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderMapper  extends BaseMapper<Orders> {
    @Insert("<script>"+"INSERT INTO t_order (uid,recv_name,recv_phone,recv_province,recv_city,recv_area, recv_address,total_price,status,order_time,pay_time,created_user,created_time,modified_user,modified_time) VALUES ( "+ "#{uid},#{recvName},#{recvPhone},#{recvProvince},#{recvCity},#{recvArea},#{recvAddress},#{totalPrice},#{status},#{orderTime},#{payTime},#{createdUser},#{createdTime},#{modifiedUser},#{modifiedTime} )"+"</script>")
    @Options(useGeneratedKeys = true, keyProperty = "oid")
    Integer insertOrders(Orders order);

    @Select("select t_order.oid, t_order.recv_name, t_order.created_time, t_order_item.image,t_order_item.title, t_order_item.price, t_order_item.num, t_order_item.pid,\n" +
            "t_production.uid\n" +
            "from t_order\n" +
            "left join t_order_item\n" +
            "on t_order.oid = t_order_item.oid\n" +
            "left join t_production\n" +
            "on t_order_item.pid = t_production.id\n" +
            "where t_order.oid\n" +
            "in (select oid from t_order where t_order.uid = #{uid}) and t_order.status <> -1")
    List<OrderVO> selectOrderVO(Integer uid);

    @Select("select * from t_order where oid = #{oid}")
    Orders selectById(int oid);

}
